package com.huang.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.UUID;


/*
	测试session和cookies
 */
@WebServlet(name = "session", urlPatterns = {"/session"})
public class SessionServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		System.out.println("获取客户端的请求");
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html");

		String userName = req.getParameter("userName");
		String password = req.getParameter("password");

		//服务端要记住登录状态，admin用户已经登陆成功,创建session
		HttpSession session = req.getSession();

		//给session中存东西
//		session.setAttribute("admin", "admin");


		//登录，业务逻辑处理完成
		if ("admin".equals(userName) && "111111".equals(password)) {



			//告诉客户端，登陆成功
			resp.getWriter().println("succeed...");
		}else{
			resp.getWriter().println("用户账号或密码错误");
		}




	}
}
